package day16;

public class TestThread2 {
    public static void main(String[] args) {
        TicketT2 t1 = new TicketT2();
        TicketT2 t2 = new TicketT2();
        TicketT2 t3 = new TicketT2();
        TicketT2 t4 = new TicketT2();

        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}



class TicketT2 extends Thread {
    static int tickets = 100;

    @Override
    public void run() {
        while(true){
            synchronized (TicketT2.class) {
                if (tickets > 0) {
                    try{
                        Thread.sleep(10);
                    }catch(InterruptedException e){
                        e.printStackTrace();
                    }
                    System.out.println(getName() + "=" + tickets--);
                }
                if (tickets <= 0) break;
            }
        }
    }
}